{__NOLAYOUT__}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link rel="stylesheet" type="text/css" href="/agent/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="/agent/css/renzheng.css"/>
    <script type="text/javascript" src="/agent/js/jquery.1.9.1.js" ></script>
    <script type="text/javascript" src="/agent/js/rem.js" ></script>
    <script type="text/javascript" src="/agent/js/layer.js"></script>
    <link rel="stylesheet" type="text/css" href="/agent/css/layer.css" />
    <title>账号认证</title>
</head>
<body style="background-color: #fff;">
<div style="padding: 1rem 0.3rem;font-size: 0.33rem;">查看代理合同正确填写以下信息</div>
<form name="form1" id="form1" action="/agent/login/registered" method="post">
    <ul>
        <li>
            <input style="width: 100%;height: 0.7rem;" data-arr="false" type="text" name="row[agent_name]" id="name" value="" placeholder="代理商名称" />
        </li>
        <li>
            <input style="width: 100%;height: 0.7rem;" data-arr="false" type="number" name="row[agent_phone]" id="tel" value="" placeholder="手机号码" />
        </li>
        <li style="position: relative;">
            <input style="width: 65%;height: 0.7rem;" data-arr="false" type="number" name="row[captcha]" id="code" value="" placeholder="手机验证码" />
            <div class="huoqu">获取验证码</div>
            <!--<div class="gray">{{count}}秒后重新获取</div>-->
        </li>
        <input class="button" id="sub" type="submit"  value="提交认证"/>
    </ul>
</form>
</body>
<script>
    //获取验证码
  $('.huoqu').click(function() {
    var tel = $('#tel').val();
    if($('#tel').attr('data-arr') == 'false')
    {
      layer.open({
        content: '请输入正确的手机号码',
        skin: 'msg',
        time: 2 //2秒后自动关闭
      });
      return false;
    }
    if(!(/^1[3456789]\d{9}$/.test(tel))) {
      layer.open({
        content: '请输入正确的手机号码',
        skin: 'msg',
        time: 2 //2秒后自动关闭
      });
      return false;
    }
    $.ajax({
      type: 'post',
      url:"/api/sms/send" ,
      data:{mobile:tel},
      success: function(data){
        if(data.code != 1){
          layer.open({
            content:data.msg ,
            skin: 'msg',
            time: 2 //2秒后自动关闭
          });
          return false
        }else{
          var count = 60;
          const countDown = setInterval(() => {
            if (count === 0) {
              $('.huoqu').text('重新发送').removeAttr('disabled');
              $('.huoqu').css({
                background: '#f3494c',
                color: '#fff',
              });
              clearInterval(countDown);
            } else {
              $('.huoqu').attr('disabled', true);
              $('.huoqu').css({
                background: '#eee',
                color: '#333',
              });
              $('.huoqu').text(count + '秒后可重新获取');
            }
            count--;
          }, 1000);
        }
      }
    });
  });
  //验证代理商名称
  $("#name").mouseout(function(){
    var name = $('#name').val();
    if(name == ""||name == null){
      layer.open({
        content:'名称不能为空' ,
        skin: 'msg',
        time: 2 //2秒后自动关闭
      });
      return false;
    }
    check({agent_name:name},'#name');
  });
  //验证代理商手机号
  $("#tel").mouseout(function(){
    var tel = $('#tel').val();
    console.log(tel)
    if(!(/^1[3456789]\d{9}$/.test(tel))) {
      layer.open({
        content: '请输入正确的手机号码',
        skin: 'msg',
        time: 2 //2秒后自动关闭
      });
      return false;
    }
    check({agent_phone:tel},'#tel');
  });
  //验证码验证
  $('#code').mouseout(function () {
    var code = $(this).val();
    var mobile = $('#tel').val();
    if(!code)
    {
      layer.open({
        content: '请输入正确的验证码',
        skin: 'msg',
        time: 2 //2秒后自动关闭
      });
      return false;
    }
    //ajax 请求是否为true
    $.ajax({
      type: 'post',
      url:"/api/sms/check" ,
      data:{mobile:mobile,captcha:code},
      success: function(data){
        if(data.code == 1){
          //验证成功！
          $('#code').attr('data-arr',true);
          $('#code').css('border','1px solid green');
          return true;
        }
        layer.open({
          content:data.msg ,
          skin: 'msg',
          time: 2 //2秒后自动关闭
        });
        $('#code').css('border','1px solid red');
        $('#code').attr('data-arr',false);
        return false;
      }
    });
  });
  function check(data,id)
  {
    //ajax 请求是否为true
    $.ajax({
      type: 'post',
      url:"/agent/login/check" ,
      data:data,
      success: function(data){
        if(data.code == 1){
          //验证成功！
          $(id).attr('data-arr',true);
          $(id).css('border','1px solid green');
          return true;
        }
        layer.open({
          content:data.msg ,
          skin: 'msg',
          time: 2 //2秒后自动关闭
        });
        $(id).css('border','1px solid red');
        $('#code').attr('data-arr',false);
        return false;
      }
    });
  }
  //表单提交
  $('#sub').click(function(){
    var name = $('#name').attr('data-arr');
    var tel = $('#tel').attr('data-arr');
    var code = $('#code').attr('data-arr');
    if(name == 'true' && tel == 'true' && code == 'true')
    {
      $('#form1').submit();
      return true;
    }
    console.log('表单提交');
    return false;

  });
</script>
</html>
